$(function () {
	var AllFormData = [];
	// 授权注册
	$("#authAdd").click(function () {
		layer.open({
			type: 2,
			title: "授权注册",
			area: ['600px', '380px'],
			content: ['./authAdd.html', 'no']
		});

	})

	var pageNum = 1, pageSize = 10, dataCount = 0;
	let S_arr = []
	function requestData() {
		$.ajax({
       timeout:30000,
			url: window.Http + "/auth/code/list",
			type: 'GET',
			headers: {
				'Authorization': "Bearer " + sessionStorage.getItem('Token')
			},
			data: { pageNum, pageSize, userId: sessionStorage.getItem('UserId') },
			success: function (res) {
				if (res.code == 200) {
					$("#authorizationTable tbody").empty()
					if (res.rows && res.rows.length > 0) {
						let html = "";
						let statushtml = "";
						let state = "正常";
						let herfUrl = "";
						// let productPrice ; // 产品价格
						res.rows.forEach(function (val, index) {
							if (val.goodsType == 1) {
								herfUrl = "./productDetail.html?serverId=" + val.goodsId + "&goodsType=" + val.goodsType;
							} else {
								herfUrl = "./productDetail.html?directoryId=" + val.goodsId + "&goodsType=" + val.goodsType;
							}
							switch (val.status || 0) {
								case -1:
									state = "待审核";
									statushtml = `<td><a class="layui-btn layui-btn-xs text-white mr-2">详情</a></td>`;
									break;
								case 0:
									state = "已通过";
									statushtml = `<td><a class="layui-btn layui-btn-xs text-white mr-2">详情</a></td>`;
									break;
								case 1:
									state = "已拒绝";
									statushtml = `<td><a class="layui-btn layui-btn-xs text-white mr-2">详情</a></td>`;
									break;
								default:
									break;
							}
							let type = {
								'0': '查看数据通道',
								'1': '查看数据产品',
								'2': '授权注册数据通道',
								'4': '授权注册产品',
							}
							html += `<tr>
									<th scope="row">`+ (index + 1) + `</th>
									<td>`+ val.createBy + `</td>
									<td>`+ val.createTime + `</td>
									<td>`+ `${val.authType ? type[val.authType]:"—"}` + `</td>
									<td>`+ `${val.authSourceName || '—'}` + `</td>
									<td>`+ `${val.authUserName || '—'}` + `</td>
									<td>`+ state + `</td>
									<td>`+ `${val.authCode||'—'}` + `</td>
									<td>`+ `${val.remark||'—'}` + `</td>
									
								</tr>`
							S_arr.push(val.id)
						})
						$("#authorizationTable tbody").append(html);
					} else {
						let html = `<tr><td scope="row" colspan="8" style="text-align:center">暂无数据</td></tr>`
						$("#authorizationTable tbody").append(html);
					}
					dataCount = res.total || 0;
					if(pageNum == 1){
						layui.laypage.render({
							elem: 'authorizationTablePage', //注意，这里的 test1 是 ID，不用加 # 号
							count: dataCount, //数据总数，从服务端得到
							limit: pageSize,
							jump: function (obj, first) {
								if(!first){
								  pageNum = obj.curr;
								  pageSize = obj.limit;
								  requestData();
								}
							}
						});
					}
				}

			}
		})
	}
	requestData();

})
